package com.wordutil;

import com.wordutil.wordentity.GenerateConfig;
import org.apache.commons.io.IOUtils;
import org.apache.poi.hwpf.usermodel.Table;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipOutputStream;

/**
 * @Author YongQiang
 * @Date 2021/4/6 14:55
 * @Version 1.0
 */
public class WordService {

    public static void generateFile(Table table, GenerateConfig generateParam) throws Exception {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ZipOutputStream zip = new ZipOutputStream(outputStream);
        GenUtils.generatorCode(table, generateParam, zip);

        IOUtils.closeQuietly(zip);
        byte[] bytes = outputStream.toByteArray();
        FileOutputStream fileOutputStream=new FileOutputStream(generateParam.getOutFilePath()+"/"+generateParam.getOutFileName());
        fileOutputStream.write(bytes);
    }
}
